package com.hdf.etdemo.view.progress;

import java.util.Timer;
import java.util.TimerTask;
import com.hdf.easytools.base.EasyToolsActivity;
import com.hdf.easytools.view.progress.CustomView;
import com.hdf.easytools.view.progress.NumberProgressBar;
import com.hdf.easytools.view.progress.NumberProgressBar.OnProgressBarListener;
import com.hdf.etdemo.R;
import com.hdf.etdemo.R.id;
import com.hdf.etdemo.R.layout;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Toast;

public class ProgressActivity extends EasyToolsActivity implements
		OnProgressBarListener {

	private Timer timer;
	private NumberProgressBar bnp;
	private CustomView customView = null;
	private int porcess=0;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		/** 设置标题显示 */
		this.TitleVisib(0, 1, 1, 0, 0);
		/** 绑定标题点击事件 */
		this.TitleClick(0, 1, 0, 0, 0);
		/** 设置标题样式ʽ */
		this.TitleStyle(null, R.drawable.et_back, "各种进度", null, 0);

		setContentView(R.layout.activity_progress);
		bnp = (NumberProgressBar) findViewById(R.id.numberbar1);
		bnp.setOnProgressBarListener(this);
		customView = (CustomView) findViewById(R.id.customView);
		timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				runOnUiThread(new Runnable() {
					@Override
					public void run() {
						bnp.incrementProgressBy(1);
						++porcess;
						customView.setProgress(porcess);
					}
				});
			}
		}, 1000, 100);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		timer.cancel();
	}

	@Override
	public void onProgressChange(int current, int max) {
		if (current == max) {
			Toast.makeText(ProgressActivity.this, "加载完成", 30).show();
			timer.cancel();
			// bnp.setProgress(0);
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.left_img:
			finish();
			break;

		default:
			break;
		}
	}

}
